package com.njwb.day15.zqzb.ios.io3;

import java.io.*;

public class BufferedReaderDemo01 {
    public static void main(String[] args) {
        BufferedReader bufferedReader = null ;
        Reader reader = null;
        try {
            //实例化的时候，先实例化节点流，然后在实例化过滤流
            reader = new FileReader(new File("src/helloworld.txt"));
            bufferedReader = new BufferedReader(reader);
            String line = null ;
            int count = 0 ;
            while((line=bufferedReader.readLine())!=null) {
                System.out.println(line);
                count++;
            };
            System.out.println("一共读取了"+count+"行数据");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            //关闭的时候倒着关闭
            if(bufferedReader!=null) {
                try {
                    bufferedReader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if(reader!=null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }


    }
}
